package com.qdxwx.manage.controller.member;

import com.qdxwx.common.page.PageRequest;
import com.qdxwx.common.page.TableDataInfo;
import com.qdxwx.common.utils.TKConvert;
import com.qdxwx.common.utils.TKString;
import com.qdxwx.data.service.member.MemberTypeService;
import com.qdxwx.common.annotation.Permissions;
import com.qdxwx.manage.controller.BaseController;
import com.qdxwx.models.member.MemberType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 会员类型Controller
 * Qdx NetSchool Platform
 * @author qdxwx
 * @updateTime 2022/5/25
 * @description
 */
@Controller
@RequestMapping("/member/type")
public class MemberTypeController extends BaseController {
    @Autowired
    private MemberTypeService memberTypeService;

    @Permissions("member:type:list")
    @GetMapping("/list.html")
    public String list() {
        return "member/member-type-list";
    }

    /**
     * 查询会员课程列表
     */
    @PostMapping("/list.json")
    @ResponseBody
    public TableDataInfo list(HttpServletRequest request) {
        request.getParameter("status");
        MemberType memberType = new MemberType();
        memberType.setTitle(TKString.queryKey(request.getParameter("title")));
        memberType.setStatus(TKConvert.toInteger(request.getParameter("status"), null));
        List<MemberType> list = memberTypeService.getList(memberType, PageRequest.form(request));
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(0);
        rspData.setRows(list);
        rspData.setTotal(memberTypeService.count(memberType));
        return rspData;
    }

}
